package com.bz.xtcx.manager.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bz.xtcx.manager.comom.XtcxException;
import com.bz.xtcx.manager.entity.*;
import com.bz.xtcx.manager.persist.conditions.*;
import com.bz.xtcx.manager.persist.paging.PageResponse;
import com.bz.xtcx.manager.service.*;
import com.bz.xtcx.manager.utils.KeyValueTransUtil;
import com.bz.xtcx.manager.utils.WzEncryptUtil;
import com.bz.xtcx.manager.utils.WzHttpUtil;
import com.bz.xtcx.manager.utils.WzStrUtil;
import com.bz.xtcx.manager.vo.VoCheck;
import com.bz.xtcx.manager.vo.VoResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.crypto.SecretKey;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Api(value = "IndexController")
@RestController
@RequestMapping("/index")
public class IndexController {
    /** 日志. */
    private final Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Autowired
    private IIndexService indexService;

    @Autowired
    private ICmsMeetingService cmsMeetingService;

    @Autowired
    private ICmsSharePlatformService cmsSharePlatformService;

    @Autowired
    private ILibService libService;

    @Autowired
    private IDataService dataService;

    @Value("${file.tomcatPath}")
    private String tomcatPath;

    @ApiOperation(value = "根据父节点获得所有子节点信息", httpMethod = "GET", notes = "如果父节点是目录，则获取其下子目录或子栏目，如果父节点是栏目，则获取其下内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentCode", value = "父节点Code", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "keyStr", value = "关键字", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/items"})
    public VoResponse getItemsByParentCategoryCode(
            @RequestParam(value = "parentCode", required = true) String parentCode,
            @RequestParam(value = "keyStr", required = false) String keyStr,
            @RequestParam(value = "loadAll", required = false, defaultValue = "false") Boolean loadAll,
            @RequestParam(value = "needPaging", required = true, defaultValue = "true") Boolean needPaging,
            @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        VoResponse resp = new VoResponse();
        // 参数检查
        if (WzStrUtil.isBlank(parentCode)) {
            resp.setFail(resp);
            resp.setMessage("参数分类Code不能为空");
            return resp;
        }
        boolean usedLoadAll = loadAll;
        if (null == loadAll) {
            usedLoadAll = false;
        }
        boolean usedNeedPaging = needPaging;
        if (null == needPaging) {
            usedNeedPaging = false;
        }
        if (usedNeedPaging && (0 >= currPage || 0 >= pageSize)) {
            resp.setFail(resp);
            resp.setMessage("分页查询缺少参数");
            return resp;
        }
        // 查询当前栏目
        try {
            CmsCategory parentCategory = indexService.getCategoryByCode(parentCode);
            if (null == parentCategory || WzStrUtil.isBlank(parentCategory.getId())) {
                resp.setFail(resp);
                resp.setMessage("Code对应分类不存在");
                return resp;
            }
            if (0 == parentCategory.getTypeId()) {
                CategoryCondition cateCond = new CategoryCondition();
                cateCond.setCode(parentCode);
                cateCond.setNeedPaging(usedNeedPaging);
                cateCond.setLoadAll(usedLoadAll);
                cateCond.setCurrPage(currPage);
                cateCond.setPageSize(pageSize);
                PageResponse<CmsCategory> categoryLs = indexService.listCategoryByParentCode(cateCond);
                resp.setSuccess(resp);
                resp.setData(categoryLs);
                return resp;
            } else if (1 == parentCategory.getTypeId()) {
                ContentCondition contCond = new ContentCondition();
                contCond.setCategoryCode(parentCode);
                contCond.setKeyStr(keyStr);
                contCond.setNeedPaging(usedNeedPaging);
                contCond.setLoadAll(usedLoadAll);
                contCond.setCurrPage(currPage);
                contCond.setPageSize(pageSize);
                contCond.setCheckStatus(1);
                contCond.setReadable(1);
                PageResponse<CmsContent> contentLs = indexService.listArticleByParentCode(contCond);
                resp.setSuccess(resp);
                resp.setData(contentLs);
                return resp;
            } else {
                resp.setFail(resp);
                resp.setMessage("分类必须是目录或栏目");
                return resp;
            }
        } catch (XtcxException e) {
            logger.error("查询错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("查询错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "根据ID获得内容", httpMethod = "GET", notes = "根据ID查询内容信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "artId", value = "内容ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/article/{artId}"})
    public VoResponse getArticleById(@PathVariable(value = "artId", required = true) String artId) {
        VoResponse resp = new VoResponse();
        if (WzStrUtil.isBlank(artId)) {
            resp.setFail(resp);
            resp.setMessage("内容ID不能为空");
            return resp;
        }
        try {
            // 更新clicks，clicks自加1
            indexService.updArticleClicks(artId);
            // 查询文章新的内容
            CmsContent contentData = indexService.findArticleById(artId);
            if (null == contentData) {
                resp.setFail(resp);
                resp.setMessage("未查询到内容");
                return resp;
            } else {
                resp.setSuccess(resp);
                resp.setData(contentData);
                return resp;
            }
        } catch (XtcxException e) {
            logger.error("查询错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("查询错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "根据关键字查询内容", httpMethod = "GET", notes = "根据关键字查询内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyStr", value = "关键字", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "recommend", value = "推荐", dataType = "Integer", required = false, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/articles"})
    public VoResponse listArticles(@RequestParam(value = "keyStr", required = false) String keyStr,
           @RequestParam(value = "recommend", required = false) Integer recommend,
           @RequestParam(value = "loadAll", required = false, defaultValue = "false") Boolean loadAll,
           @RequestParam(value = "needPaging", required = true, defaultValue = "true") Boolean needPaging,
           @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
           @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        VoResponse resp = new VoResponse();
        boolean usedLoadAll = loadAll;
        if (null == loadAll) {
            usedLoadAll = false;
        }
        boolean usedNeedPaging = needPaging;
        if (null == needPaging) {
            usedNeedPaging = false;
        }
        if (usedNeedPaging && (0 >= currPage || 0 >= pageSize)) {
            resp.setFail(resp);
            resp.setMessage("分页查询缺少参数");
            return resp;
        }
        ContentCondition contCond = new ContentCondition();
        contCond.setKeyStr(keyStr);
        contCond.setRecommend(recommend);
        contCond.setNeedPaging(usedNeedPaging);
        contCond.setLoadAll(usedLoadAll);
        contCond.setCurrPage(currPage);
        contCond.setPageSize(pageSize);
        contCond.setCheckStatus(1);
        contCond.setReadable(1);

        try {
            // 查询文章新的内容
            PageResponse<CmsContent> contentLs = indexService.listArticlesByKeyStrOrRecommend(contCond);
            if (null == contentLs || null == contentLs.getRows() || 0 == contentLs.getRows().size()) {
                resp.setMessage("未查询到内容");
                return resp;
            } else {
                resp.setSuccess(resp);
                resp.setData(contentLs);
                return resp;
            }
        } catch (XtcxException e) {
            logger.error("查询错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("查询错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "根据ID增加内容的点击数", httpMethod = "GET", notes = "根据ID增加内容的点击数，点击数自增1")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "artId", value = "内容ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/article/{artId}/addclicks"})
    public VoResponse updArticleClicksById(@PathVariable(value = "artId", required = true) String artId) {
        VoResponse resp = new VoResponse();
        if (WzStrUtil.isBlank(artId)) {
            resp.setFail(resp);
            resp.setMessage("内容ID不能为空");
            return resp;
        }
        try {
            // 更新clicks，clicks自加1
            indexService.updArticleClicks(artId);
            // 查询文章新的内容
            CmsContent contentData = indexService.findArticleById(artId);
            if (null == contentData) {
                resp.setFail(resp);
                resp.setMessage("未查询到内容");
                return resp;
            } else {
                resp.setSuccess(resp);
                resp.setData(contentData);
                return resp;
            }
        } catch (XtcxException e) {
            logger.error("查询错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("查询错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "获得活动列表", httpMethod = "GET", notes = "获得活动列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kw", value = "关键字", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/exchanges"})
    public VoResponse getExchanges(
            @RequestParam(value = "kw", required = false) String kw,
            @RequestParam(value = "loadAll", required = false, defaultValue = "false") Boolean loadAll,
            @RequestParam(value = "needPaging", required = true, defaultValue = "true") Boolean needPaging,
            @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        VoResponse resp = new VoResponse();
        // 参数检查
        boolean usedLoadAll = loadAll;
        if (null == loadAll) {
            usedLoadAll = false;
        }
        boolean usedNeedPaging = needPaging;
        if (null == needPaging) {
            usedNeedPaging = false;
        }
        if (usedNeedPaging && (0 >= currPage || 0 >= pageSize)) {
            resp.setFail(resp);
            resp.setMessage("分页查询缺少参数");
            return resp;
        }

        // 查询活动
        try {
            ExchangeCondition exCond = new ExchangeCondition();
            exCond.setKeyStr(kw);
            exCond.setNeedPaging(usedNeedPaging);
            exCond.setLoadAll(usedLoadAll);
            exCond.setCurrPage(currPage);
            exCond.setPageSize(pageSize);
            exCond.setCheckStatus(1);
            exCond.setReadable(1);
            PageResponse<CmsExchanges> exLs = indexService.listExcanges(exCond);
            resp.setSuccess(resp);
            resp.setData(exLs);
            return resp;
        } catch (XtcxException e) {
            logger.error("查询错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("查询错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "根据ID获得活动内容", httpMethod = "GET", notes = "根据ID查询活动内容信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "exId", value = "活动ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/exchange/{exId}"})
    public VoResponse getExchangeById(@PathVariable(value = "exId", required = true) String exId) {
        VoResponse resp = new VoResponse();
        if (WzStrUtil.isBlank(exId)) {
            resp.setFail(resp);
            resp.setMessage("活动ID不能为空");
            return resp;
        }
        try {
            // 查询文章新的内容
            CmsExchanges exData = indexService.findExchangeById(exId);
            if (null == exData) {
                resp.setFail(resp);
                resp.setMessage("活动不存在");
                return resp;
            } else {
                resp.setSuccess(resp);
                resp.setData(exData);
                return resp;
            }
        } catch (XtcxException e) {
            logger.error("查询错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("查询错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "活动报名", httpMethod = "POST", notes = "保存报名信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "exId", value = "活动ID", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "loginUserId", value = "登录用户ID", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "姓名", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "workplace", value = "单位", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "job", value = "职称", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "联系电话", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "email", value = "联系邮箱", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "addr", value = "联系地址", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "memo", value = "备注", dataType = "String", required = false, paramType = "query")
    })
    @PostMapping(value = {"/activity/enroll"})
    public VoResponse enrollActivity (
            @RequestParam(value = "exId", required = true) String exId,
            @RequestParam(value = "loginUserId", required = true) String loginUserId,
            @RequestParam(value = "name", required = true) String name,
            @RequestParam(value = "workplace", required = false) String workplace,
            @RequestParam(value = "job", required = false) String job,
            @RequestParam(value = "phone", required = true) String phone,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "addr", required = false) String addr,
            @RequestParam(value = "memo", required = false) String memo
            ) {
        VoResponse resp = new VoResponse();
        if (WzStrUtil.isBlank(exId)) {
            resp.setFail(resp);
            resp.setMessage("活动ID不能为空");
            return resp;
        }
        if (WzStrUtil.isBlank(loginUserId)) {
            resp.setFail(resp);
            resp.setMessage("活动报名请先登录");
            return resp;
        }
        if (WzStrUtil.isBlank(name) || WzStrUtil.isBlank(phone)) {
            resp.setFail(resp);
            resp.setMessage("请填写报名人姓名和电话");
            return resp;
        }
        try {
            // 组织活动报名信息
            CmsExchangesEnroll insertVo = new CmsExchangesEnroll();
            insertVo.setExchangesId(exId);
            insertVo.setUserId(loginUserId);
            insertVo.setName(name);
            insertVo.setPhone(phone);
            insertVo.setWorkplace(workplace);
            insertVo.setJob(job);
            insertVo.setEmail(email);
            insertVo.setAddr(addr);
            insertVo.setMemo(memo);
            insertVo.setEnrollDate(new Date());
            return indexService.enrollExchange(insertVo);
        } catch (XtcxException e) {
            logger.error("查询错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("查询错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "根据栏目Code获得资源库列表", httpMethod = "GET", notes = "根据栏目Code获得资源库信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resType", value = "资源库栏目Code（资源类型）", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/resources"})
    public Object getResourcesByCategoryCode(
            @RequestParam(value = "resType", required = true) String resType,
            @RequestParam(value = "loadAll", required = false, defaultValue = "false") boolean loadAll,
            @RequestParam(value = "needPaging", required = true, defaultValue = "true") boolean needPaging,
            @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        return null;
    }

    @ApiOperation(value = "根据ID获得资源内容", httpMethod = "GET", notes = "根据ID查询资源内容信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resType", value = "资源库栏目Code（资源类型）", dataType = "String", required = true, paramType = "path"),
            @ApiImplicitParam(name = "resId", value = "资源ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/resource/{resType}/{resId}"})
    public Object getResourceById(
            @PathVariable(value = "resType", required = true) String resType,
            @PathVariable(value = "resId", required = true) String resId) {
        return null;
    }
    
    @ApiOperation(value = "获得资源库专家列表", httpMethod = "GET", notes = "获得资源库专家分页列表信息")
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "objName", value = "根据专家姓名", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objCountry", value = "地域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objDomain", value = "领域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "province", value = "省", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "city", value = "城市", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "zone", value = "区", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/lib/experts"})
    public VoResponse getExperts(
    		@RequestParam(value = "objName", required = false) String objName,
            @RequestParam(value = "objCountry", required = false) String objCountry,
            @RequestParam(value = "objDomain", required = false) String objDomain,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "zone", required = false) String zone,
            @RequestParam(value = "loadAll", required = false, defaultValue="true") boolean loadAll,
            @RequestParam(value = "needPaging", required = true) boolean needPaging,
            @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        VoResponse resp = new VoResponse();
        LibCondition cc = new LibCondition();
        cc.setObjName(objName);
        cc.setObjCountry(objCountry);
        cc.setObjDomain(objDomain);
        cc.setProvince(province);
        cc.setCity(city);
        cc.setZone(zone);
        cc.setLoadAll(loadAll);
        cc.setNeedPaging(needPaging);
        if(needPaging) {
        	cc.setCurrPage(currPage);
            cc.setPageSize(pageSize);
        }
        try {
        	resp.setData(indexService.listExperts(cc));
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "根据ID获得专家信息", httpMethod = "GET", notes = "根据ID获得专家信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resId", value = "专家ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/lib/experts/{resId}"})
    public VoResponse getExpertById(@PathVariable(value = "resId", required = true) String resId) {
        VoResponse resp = new VoResponse();
        try {
            LibExpert model = indexService.findExpertById(resId);
            User user = indexService.getUser();
            if (user == null) {
                resp.setTimeout(resp);
                resp.setData(model);
            } else {
                resp.setData(model);
            }
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "获得资源库企业列表", httpMethod = "GET", notes = "获得资源库企业分页列表信息")
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "objName", value = "根据企业名称", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objCountry", value = "地域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objDomain", value = "领域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "province", value = "省", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "city", value = "城市", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "zone", value = "区", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/lib/Enterprises"})
    public VoResponse getEnterprises(
    		@RequestParam(value = "objName", required = false) String objName,
            @RequestParam(value = "objCountry", required = false) String objCountry,
            @RequestParam(value = "objDomain", required = false) String objDomain,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "zone", required = false) String zone,
            @RequestParam(value = "loadAll", required = false, defaultValue="true") boolean loadAll,
            @RequestParam(value = "needPaging", required = true) boolean needPaging,
            @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        VoResponse resp = new VoResponse();
        LibCondition cc = new LibCondition();
        cc.setObjName(objName);
        cc.setObjCountry(objCountry);
        cc.setObjDomain(objDomain);
        cc.setProvince(province);
        cc.setCity(city);
        cc.setZone(zone);
        cc.setLoadAll(loadAll);
        cc.setNeedPaging(needPaging);
        if(needPaging) {
        	cc.setCurrPage(currPage);
            cc.setPageSize(pageSize);
        }
        try {
        	resp.setData(indexService.listEnterprises(cc));
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "根据ID获得企业信息", httpMethod = "GET", notes = "根据ID获得企业详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resId", value = "企业ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/lib/Enterprise/{resId}"})
    public VoResponse getEnterpriseById(@PathVariable(value = "resId", required = true) String resId) {
        VoResponse resp = new VoResponse();
        try {
        	resp.setData(indexService.findEnterpriseById(resId));
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }

    @ApiOperation(value = "获得资源库服务机构列表", httpMethod = "GET", notes = "获得资源库服务机构分页列表信息")
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "objName", value = "根据服务机构名称", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objCountry", value = "地域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objDomain", value = "领域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "province", value = "省", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "city", value = "城市", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "zone", value = "区", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/lib/Services"})
    public VoResponse getServices(
    		@RequestParam(value = "objName", required = false) String objName,
            @RequestParam(value = "objCountry", required = false) String objCountry,
            @RequestParam(value = "objDomain", required = false) String objDomain,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "zone", required = false) String zone,
            @RequestParam(value = "loadAll", required = false, defaultValue="true") boolean loadAll,
            @RequestParam(value = "needPaging", required = true) boolean needPaging,
            @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        VoResponse resp = new VoResponse();
        LibCondition cc = new LibCondition();
        cc.setObjName(objName);
        cc.setObjCountry(objCountry);
        cc.setObjDomain(objDomain);
        cc.setProvince(province);
        cc.setCity(city);
        cc.setZone(zone);
        cc.setLoadAll(loadAll);
        cc.setNeedPaging(needPaging);
        if(needPaging) {
        	cc.setCurrPage(currPage);
            cc.setPageSize(pageSize);
        }
        try {
        	resp.setData(indexService.listServices(cc));
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "根据ID获得服务机构信息", httpMethod = "GET", notes = "根据ID获得服务机构详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resId", value = "服务机构ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/lib/Service/{resId}"})
    public VoResponse getServiceById(@PathVariable(value = "resId", required = true) String resId) {
        VoResponse resp = new VoResponse();
        try {
            LibServices model = indexService.findServiceById(resId);
            User user = indexService.getUser();
            if (user == null) {
                resp.setTimeout(resp);
                resp.setData(model);
            } else {
                resp.setData(model);
            }
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "获得资源库高校院所列表", httpMethod = "GET", notes = "获得资源库高校院所分页列表信息")
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "objName", value = "根据高校院所名称", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objCountry", value = "地域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "province", value = "省", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "city", value = "城市", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "zone", value = "区", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/lib/Colleges"})
    public VoResponse getColleges(
    		@RequestParam(value = "objName", required = false) String objName,
            @RequestParam(value = "objCountry", required = false) String objCountry,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "zone", required = false) String zone,
            @RequestParam(value = "loadAll", required = false, defaultValue="true") boolean loadAll,
            @RequestParam(value = "needPaging", required = true) boolean needPaging,
            @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        VoResponse resp = new VoResponse();
        LibCondition cc = new LibCondition();
        cc.setObjName(objName);
        cc.setObjCountry(objCountry);
        cc.setProvince(province);
        cc.setCity(city);
        cc.setZone(zone);
        cc.setLoadAll(loadAll);
        cc.setNeedPaging(needPaging);
        if(needPaging) {
        	cc.setCurrPage(currPage);
            cc.setPageSize(pageSize);
        }
        try {
        	resp.setData(indexService.listColleges(cc));
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "根据ID获得高校院所信息", httpMethod = "GET", notes = "根据ID获得高校院所详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resId", value = "服务机构ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/lib/College/{resId}"})
    public VoResponse getCollegeById(@PathVariable(value = "resId", required = true) String resId) {
        VoResponse resp = new VoResponse();
        try {
        	resp.setData(indexService.findCollegeById(resId));
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "获得资源库需求列表", httpMethod = "GET", notes = "获得资源库需求分页列表信息")
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "objName", value = "根据需求名称/企业名称", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objCountry", value = "地域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objDomain", value = "领域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "province", value = "省", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "city", value = "城市", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "zone", value = "区", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/lib/Requirements"})
    public VoResponse getRequirements(
    		@RequestParam(value = "objName", required = false) String objName,
            @RequestParam(value = "objCountry", required = false) String objCountry,
            @RequestParam(value = "objDomain", required = false) String objDomain,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "zone", required = false) String zone,
            @RequestParam(value = "loadAll", required = false, defaultValue="true") boolean loadAll,
            @RequestParam(value = "needPaging", required = true) boolean needPaging,
            @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        VoResponse resp = new VoResponse();
        LibCondition cc = new LibCondition();
        cc.setObjName(objName);
        cc.setObjCountry(objCountry);
        cc.setObjDomain(objDomain);
        cc.setProvince(province);
        cc.setCity(city);
        cc.setZone(zone);
        cc.setLoadAll(loadAll);
        cc.setNeedPaging(needPaging);
        if(needPaging) {
        	cc.setCurrPage(currPage);
            cc.setPageSize(pageSize);
        }
        try {
        	resp.setData(indexService.listRequirements(cc));
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "根据ID获得需求信息", httpMethod = "GET", notes = "根据ID获得需求详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resId", value = "需求ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/lib/Requirement/{resId}"})
    public VoResponse getRequirementById(@PathVariable(value = "resId", required = true) String resId) {
        VoResponse resp = new VoResponse();
        try {
            LibRequirements requirement = indexService.findRequirementById(resId);
            User user = indexService.getUser();
            if (user == null) {
                resp.setTimeout(resp);
                resp.setData(requirement);
            } else {
                resp.setData(requirement);
            }
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "获得资源库成果列表", httpMethod = "GET", notes = "获得资源库成果分页列表信息")
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "objName", value = "根据需求名称/企业名称", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objCountry", value = "地域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "objDomain", value = "领域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "province", value = "省", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "city", value = "城市", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "zone", value = "区", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "loadAll", value = "是否加载全数据", dataType = "Boolean", required = false, defaultValue = "false", paramType = "query"),
            @ApiImplicitParam(name = "needPaging", value = "是否需要分页", dataType = "Boolean", required = true, defaultValue = "true", paramType = "query"),
            @ApiImplicitParam(name = "currPage", value = "当前页", dataType = "Integer", required = false, defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录条数", dataType = "Integer", required = false, defaultValue = "5", paramType = "query")
    })
    @GetMapping(value = {"/lib/Harvests"})
    public VoResponse getHarvests(
    		@RequestParam(value = "objName", required = false) String objName,
            @RequestParam(value = "objCountry", required = false) String objCountry,
            @RequestParam(value = "objDomain", required = false) String objDomain,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "zone", required = false) String zone,
            @RequestParam(value = "loadAll", required = false, defaultValue="true") boolean loadAll,
            @RequestParam(value = "needPaging", required = true) boolean needPaging,
            @RequestParam(value = "currPage", required = false, defaultValue = "1") int currPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize) {
        VoResponse resp = new VoResponse();
        LibCondition cc = new LibCondition();
        cc.setObjName(objName);
        cc.setObjCountry(objCountry);
        cc.setObjDomain(objDomain);
        cc.setProvince(province);
        cc.setCity(city);
        cc.setZone(zone);
        cc.setLoadAll(loadAll);
        cc.setNeedPaging(needPaging);
        if(needPaging) {
        	cc.setCurrPage(currPage);
            cc.setPageSize(pageSize);
        }
        try {
        	resp.setData(indexService.listHarvests(cc));
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }
    
    @ApiOperation(value = "根据ID获得成果信息", httpMethod = "GET", notes = "根据ID获得成果详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resId", value = "成果ID", dataType = "String", required = true, paramType = "path")
    })
    @GetMapping(value = {"/lib/Harvest/{resId}"})
    public VoResponse getHarvestById(@PathVariable(value = "resId", required = true) String resId) {
        VoResponse resp = new VoResponse();
        try {
            LibResults model= indexService.findHarvestById(resId);
            User user = indexService.getUser();
            if (user == null) {
                resp.setTimeout(resp);
                resp.setData(model);
            } else {
                resp.setData(model);
            }
		} catch (Exception e) {
			e.printStackTrace();
			resp.setFail(resp);
			resp.setMessage(e.getMessage());
		}
        return resp;
    }

    @ApiOperation(value = "登记网站访问", httpMethod = "GET", notes = "登记网站访问")
    @GetMapping(value = {"/recordvisit"})
    public VoResponse recordIndexVisit(HttpServletRequest request, HttpServletResponse response) {
        // 统计总访问量
        try {
            IndexVisiter ivVo = new IndexVisiter();
            ivVo.setIp(WzHttpUtil.getClientIP(request));
            ivVo.setVisitTime(new Date());
            VoResponse resp = indexService.recordIndexVisit(ivVo);
            return resp;
        } catch (XtcxException e) {
            logger.error("访问登记错误：" + e.getMessage(), e);
            VoResponse resp = new VoResponse();
            resp.setFail(resp);
            resp.setMessage("访问登记错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            VoResponse resp = new VoResponse();
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "统计门户网站访问量及对接数及注册用户数", httpMethod = "GET", notes = "统计门户网站访问量及对接数及注册用户数")
    @GetMapping(value = {"/vmucount"})
    public VoResponse countIndexVisitAndMeetingAndUser() {
        // 统计总访问量
        try {
            // 0 统计截止到目前的全部访问量
            // 1 统计每个IP截止到目前的访问量
            // 2 统计每天每个IP的访问量
//            VoResponse resp = indexService.countIndexVisit(0, new IndexVisiterCondition());
            VoResponse resp = indexService.countIndexVisitAndMeetingAndUser();
            return resp;
        } catch (XtcxException e) {
            logger.error("查询错误：" + e.getMessage(), e);
            VoResponse resp = new VoResponse();
            resp.setFail(resp);
            resp.setMessage("查询错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            VoResponse resp = new VoResponse();
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "地域KV接口", httpMethod = "GET", notes = "地域KV接口")
    @GetMapping(value = {"/pcaa"})
    public VoResponse loadPcaa() {
        VoResponse resp = new VoResponse();
        Map<String, Object> kvMap = new HashMap<String, Object>();
        kvMap.put("kv", KeyValueTransUtil.getPcaaKVMap());
        kvMap.put("vk", KeyValueTransUtil.getPcaaVKMap());
        resp.setData(kvMap);
        return resp;
    }

    @ApiOperation(value = "发起对接", httpMethod = "POST", notes = "用户发起对接请求")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "typeId", value = "对接类别", dataType = "Integer", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fcn", value = "发起联系人姓名", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fcp", value = "发起联系人电话", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fcm", value = "发起联系人邮箱", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "fca", value = "发起联系人地址", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "appId", value = "内容ID", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "appNote", value = "申请说明", dataType = "String", required = true, paramType = "query")
    })
    @PostMapping(value = {"/meeting/apply"})
    public VoResponse meetingApply(@RequestParam(value = "typeId", required = true) Integer typeId,
               @RequestParam(value = "fcn", required = true) String fcn,
               @RequestParam(value = "fcp", required = true) String fcp,
               @RequestParam(value = "fcm", required = true) String fcm,
               @RequestParam(value = "fca", required = false) String fca,
               @RequestParam(value = "appId", required = true) String appId,
               @RequestParam(value = "appNote", required = true) String appNote) {
        VoResponse resp = new VoResponse();
        if (null == typeId || (0 != typeId && 1 != typeId && 2 != typeId && 3 != typeId)) {
            resp.setFail(resp);
            resp.setMessage("只能进行专家、需求、成果、服务对接");
            return resp;
        }
        if (WzStrUtil.isBlank(fcn) || WzStrUtil.isBlank(fcp) || WzStrUtil.isBlank(fcm)) {
            resp.setFail(resp);
            resp.setMessage("发起联系人姓名、手机号、电子邮箱必须填写");
            return resp;
        }
        if (WzStrUtil.isBlank(appId)) {
            resp.setFail(resp);
            resp.setMessage("丢失对接内容，请重试");
            return resp;
        }
        if (WzStrUtil.isBlank(appNote)) {
            resp.setFail(resp);
            resp.setMessage("请填写申请说明，以便让对方了解您");
            return resp;
        }
        CmsMeeting cm = new CmsMeeting();
        cm.setTypeId(typeId);
        cm.setFromerContactsName(fcn);
        cm.setFromerContactsPhone(fcp);
        cm.setFromerContactsMail(fcm);
        cm.setFromerContactsAddr(fca);
        cm.setApplicationContentId(appId);
        cm.setApplicationNote(appNote);
        try {
            resp = cmsMeetingService.add(cm);
		} catch (XtcxException e) {
            logger.error("对接错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("对接错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
        return resp;
    }

    @ApiOperation(value = "查询对接信息", httpMethod = "GET", notes = "查询对接信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cd", value = "对接编号", dataType = "String", required = true, paramType = "query"),
    })
    @GetMapping("/meeting/getbycd")
    public VoResponse getByCd(@RequestParam(value = "cd", required = true) String cd) {
        VoResponse voRes = new VoResponse();
        if (WzStrUtil.isBlank(cd)) {
            voRes.setFail(voRes);
            voRes.setMessage("缺少参数");
            return voRes;
        }
        try {
            // modify by wangtao on 20190103 for 对接参数需无规律并且不做重复返回 start
            String usedCd = decryptTaCd(cd);
            CmsMeeting cmVo = cmsMeetingService.getByCd(usedCd);
            if (null == cmVo) {
                voRes.setFail(voRes);
                voRes.setMessage("未查询到对接数据");
                return voRes;
            }
            if (1 == cmVo.getCheckStatus()) {
                voRes.setFail(voRes);
                voRes.setMessage("该对接已经按同意处理完毕");
                return voRes;
            }
            if (2 == cmVo.getCheckStatus()) {
                voRes.setFail(voRes);
                voRes.setMessage("该对接已经被拒绝");
                return voRes;
            }
            if (3 == cmVo.getCheckStatus()) {
                voRes.setFail(voRes);
                voRes.setMessage("该对接已经超时");
                return voRes;
            }
            // modify by wangtao on 20190103 for 对接参数需无规律并且不做重复返回 end
            voRes.setData(cmVo);
        } catch (XtcxException e) {
            logger.error("查询错误：" + e.getMessage(), e);
            voRes.setFail(voRes);
            voRes.setMessage("查询错误：" + e.getMessage());
            return voRes;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            voRes.setFail(voRes);
            voRes.setMessage("系统错误：" + e.getMessage());
            return voRes;
        }
        return voRes;
    }

    // add by wangtao on 20190103 for 对接参数需无规律并且不做重复返回 start
    private String decryptTaCd(String taCd) {
        try {
            SecretKey sk = WzEncryptUtil.genAesKey();
            String taCdBase64 = WzEncryptUtil.decryptHexString(taCd, "utf-8");
            byte[] taCdBase64Bytes = WzEncryptUtil.base64ToByteArr(taCdBase64);
            byte[] taCdBytes = WzEncryptUtil.decryptAES(sk, taCdBase64Bytes);
            String taCdStr = new String(taCdBytes, "utf-8");
            if (WzStrUtil.isBlank(taCdStr)) {
                return taCd;
            } else {
                return taCdStr;
            }
        } catch (Exception ex) {
            return taCd;
        }
    }
    // add by wangtao on 20190103 for 对接参数需无规律并且不做重复返回 end

    @ApiOperation(value = "对接认证", httpMethod = "POST", notes = "收到对接请求后回复")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对接ID", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "agreeOrRefuse", value = "同意还是拒绝（0拒绝；1同意）", dataType = "Integer", required = true, paramType = "query"),
            @ApiImplicitParam(name = "replyTxt", value = "拒绝原因", dataType = "String", required = false, paramType = "query")
    })
    @PostMapping(value = {"/meeting/reply"})
    public VoResponse meetingReply(@RequestParam(value = "id", required = true) String id,
                @RequestParam(value = "agreeOrRefuse", required = true) Integer agreeOrRefuse,
                @RequestParam(value = "replyTxt", required = false) String replyTxt) {
        VoResponse resp = new VoResponse();
        if (WzStrUtil.isBlank(id) || null == agreeOrRefuse) {
            resp.setFail(resp);
            resp.setMessage("参数错误，请重试");
            return resp;
        }
        if (null != agreeOrRefuse && 0 != agreeOrRefuse && 1 != agreeOrRefuse) {
            resp.setFail(resp);
            resp.setMessage("请选择同意还是拒绝");
            return resp;
        }
        try {
            // add by wangtao on 20190103 for 对接问题修改 start
            CmsMeeting cmVo = cmsMeetingService.findById(id);
            if (1 == cmVo.getCheckStatus().intValue()) {
                resp.setSuccess(resp);
                resp.setMessage("已经同意对方的申请");
                return resp;
            }
            // add by wangtao on 20190103 for 对接问题修改 end
            if (0 == agreeOrRefuse) {
                String rStr = replyTxt;
                if (WzStrUtil.isBlank(rStr)) {
                    rStr = "未填写拒绝原因";
                }
                resp = cmsMeetingService.refuse(id, rStr);
            } else {
                resp = cmsMeetingService.agree(id);
            }
            // 进行回复通知
		} catch (XtcxException e) {
            logger.error("回应错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("回应错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
        return resp;
    }

    @ApiOperation(value = "查询平台设备", httpMethod = "GET", notes = "查询平台设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kw", value = "关键字", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "domain", value = "领域", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "level", value = "级别", dataType = "String", required = false, paramType = "query")
    })
    @GetMapping(value = {"/shareplatform"})
    public VoResponse loadSharePlatforms(@RequestParam(value = "kw", required = false) String kw,
             @RequestParam(value = "domain", required = false) String domain,
             @RequestParam(value = "level", required = false) String level) {
        VoResponse resp = new VoResponse();
        try {
            SharePlatformCondition spfc = new SharePlatformCondition();
            spfc.setKeyStr(kw);
            spfc.setDomain(domain);
            spfc.setLevel(level);
            return cmsSharePlatformService.getAllSps(spfc);
        } catch (XtcxException e) {
            logger.error("查询平台设备错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("查询平台设备错误：" + e.getMessage());
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "资源领域获得接口", httpMethod = "GET", notes = "资源领域获得接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "资源类型", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "subType", value = "配置类型", dataType = "String", required = false, paramType = "query")
    })
    @GetMapping(value = {"/resdomain"})
    public VoResponse getResourceDomain(@RequestParam(value = "type", required = true) String type, @RequestParam(value = "subType", required = false) String subType) {
        VoResponse resp = new VoResponse();
        if (WzStrUtil.isBlank(type)) {
            resp.setFail(resp);
            resp.setMessage("资源类型缺失");
            return resp;
        }
        int formType = 0;
        if ("xq".equals(type)) {
            formType = 7;
        } else if ("cg".equals(type)) {
            formType = 6;
        } else if ("zj".equals(type)) {
            formType = 1;
        } else if ("qy".equals(type)) {
            formType = 2;
        } else if ("gx".equals(type)) {
            formType = 4;
        } else if ("fwjg".equals(type)) {
            formType = 3;
        } else {
            resp.setFail(resp);
            resp.setMessage("非法类别");
            return resp;
        }
        try {
            BusUserForm confVo =  libService.getUserForm(formType);
            if (null == confVo || WzStrUtil.isBlank(confVo.getDetail())) {
                resp.setFail(resp);
                resp.setMessage("未获得配置");
                return resp;
            }
            if (WzStrUtil.isNotBlank(subType)) {
                JSONObject o = JSON.parseObject(confVo.getDetail());
                resp.setData(o.get(subType));
            } else {
                JSONObject o = JSON.parseObject(confVo.getDetail());
                resp.setData(o);
            }
            return resp;
        } catch (Exception e) {
            logger.error("系统错误：" + e.getMessage(), e);
            resp.setFail(resp);
            resp.setMessage("系统错误：" + e.getMessage());
            return resp;
        }
    }

    @ApiOperation(value = "资源统计接口", httpMethod = "POST", notes = "资源统计接口")
    @PostMapping(value = {"/libcount"})
    public Object libBy(@RequestBody VoCheck check) {
        VoResponse resp = new VoResponse();
        if (WzStrUtil.isBlank(check.getFormType())) {
            resp.setFail(resp);
            resp.setMessage("资源类型缺失");
            return resp;
        }
        int fType = 0;
        if ("xq".equals(check.getFormType())) {
            fType = 7;
        } else if ("cg".equals(check.getFormType())) {
            fType = 6;
        } else if ("zj".equals(check.getFormType())) {
            fType = 1;
        } else if ("qy".equals(check.getFormType())) {
            fType = 2;
        } else if ("gx".equals(check.getFormType())) {
            fType = 4;
        } else if ("fwjg".equals(check.getFormType())) {
            fType = 3;
        } else {
            resp.setFail(resp);
            resp.setMessage("非法类别");
            return resp;
        }
        if(check.getSite() == null || (!check.getSite().equals("1") && !check.getSite().equals("2") && !check.getSite().equals("3"))) {
            check.setIfSite(false);
        }else {
            check.setIfSite(true);
            if(check.getSites() == null) {
                check.setSites(new ArrayList<String>());
            }
        }
        if(check.getDomain() == null ||  !check.getDomain().equals("1")) {
            check.setIfDomain(false);
        }else {
            check.setIfDomain(true);
        }
        switch(fType) {
            case 1 :
                if(check.getSex() == null ||  !check.getSex().equals("1")) {
                    check.setIfSex(false);
                }else {
                    check.setIfSex(true);
                }
                if(check.getEducation() == null ||  !check.getEducation().equals("1")) {
                    check.setIfEducation(false);
                }else {
                    check.setIfEducation(true);
                }
                if(check.getDegree() == null ||  !check.getDegree().equals("1")) {
                    check.setIfDegree(false);
                }else {
                    check.setIfDegree(true);
                }
                break;
            case 2 :
                if(check.getScale() == null ||  !check.getScale().equals("1")) {
                    check.setIfScale(false);
                }else {
                    check.setIfScale(true);
                }
                if(check.getRegType() == null ||  !check.getRegType().equals("1")) {
                    check.setIfRegType(false);
                }else {
                    check.setIfRegType(true);
                }
                if(check.getIsListed() == null ||  !check.getIsListed().equals("1")) {
                    check.setIfIsListed(false);
                }else {
                    check.setIfIsListed(true);
                }
                break;
            case 3 :
                if(check.getNature() == null ||  !check.getNature().equals("1")) {
                    check.setIfNature(false);
                }else {
                    check.setIfNature(true);
                }
                if(check.getCategory() == null ||  !check.getCategory().equals("1")) {
                    check.setIfCategory(false);
                }else {
                    check.setIfCategory(true);
                }
                break;
            case 6 :
                if (check.getStage() == null || !check.getStage().equals("1")) {
                    check.setIfStage(false);
                } else {
                    check.setIfStage(true);
                }
                break;
            case 4 :

            case 7 :
                break;
            default :
                resp.setFail(resp);
                resp.setMessage("参数验证失败");
                return resp;
        }
        try {
            resp.setData(dataService.getLibStatistics(fType, check));
        } catch (XtcxException e) {
            logger.error("资源库统计处理失败", e);
            resp.setFail(resp);
            resp.setMessage("资源库统计处理失败");
            return resp;
        } catch (Exception e) {
            logger.error("资源库统计处理系统异常", e);
            resp.setFail(resp);
            resp.setMessage("资源库统计处理系统异常");
            return resp;
        }
        return resp;
    }

    @ApiOperation(value = "根据Token获得信息", httpMethod = "GET", notes = "根据Token获得信息")
    @GetMapping(value = {"/ubyt"})
    public Object getUserByToken() {
        try {
            VoResponse resp = indexService.getUserByToken();
            return resp;
        } catch (XtcxException e) {
            logger.error("获得登录用户处理失败", e);
            VoResponse resp = new VoResponse();
            resp.setFail(resp);
            resp.setMessage("获得登录用户处理失败");
            return resp;
        } catch (Exception e) {
            logger.error("获得登录用户处理系统异常", e);
            VoResponse resp = new VoResponse();
            resp.setFail(resp);
            resp.setMessage("获得登录用户处理系统异常");
            return resp;
        }
    }
}
